Page({
  data: {
    yz_open_id:'',
    curId:'',
    content:{},
    reportInfo:{}
  },
  onLoad(e) {

    
		// console.log(getApp().globalData, 22222)
		// console.log(getApp(), 22222)
		// const {
		// 	app
		// } = getApp().getYouZanYunSdk();
		// app
		// 	.getUserInfo()
		// 	.then(({
		// 		userInfo,
		// 		state
		// 	}) => {
		// 		console.log(userInfo, state, 1111)

		// 		this.setData({
		// 			yz_open_id: userInfo.userOpenId,
		// 		})
		// 	})
    this.setData({
      curId:e.id
    })
	this.getList()
  },
  toBao(){
    
		wx.redirectTo({
      url:'/pages/reportlist/index',
    })
  },
  getList(){
	 
	//  const sdk = getApp().getYouZanYunSdk();
	 wx.request({
	   appName: "babyplanet",
	   url: "https://babyplanet.isv-dev.youzan.com/api/allergyReport/view",
	   method: "get",
	   data:{
	     id:this.data.curId
	   },
	   success: (res) => {
	     
	     console.log(res,122)
	     if (res.data.code == 200) {
	       this.setData({
	         reportInfo:res.data.data,
	         content:JSON.parse(res.data.data.content)
	       })
	 
	       for (let i = 0; i < this.data.content.fa.length; i++) {
	         let a=false
	         for (let j = 0; j < this.data.content.fa[i].list.length; j++) {
	           this.data.content.fa[i].list[j].isManualService1=false
	           if (this.data.content.fa[i].list[j].isManualService == '是') {
	             this.data.content.fa[i].list[j].isManualService1=true
	             a=true
	               break;
	           }
	       }
	       if(a){
	         break
	       }
	     }
	 
	     console.log(this.data.content.fa,1212)
	     this.setData({
	       
	       content:this.data.content
	     })
	     }else{
	       wx.showToast({
	         title: res.data.msg,
	         icon: 'none',
	         duration: 2000 //持续的时间
	       })
	     }
	   },
	   failed: (err) => {
	     console.log("err:", err);
	   },
	 }); 
  },
  onPullDownRefresh: function () {
      console.log('下拉刷新');
	  this.getList()
      // 在这里编写数据更新的逻辑
      wx.stopPullDownRefresh(); // 数据更新完成后，调用该方法停止刷新
    },
	toIndex(){
		const sdk = getApp().getYouZanYunSdk();
		
		sdk.navigate("homeDashboard", "reLaunch");
		
	},
	// onUnload(event){
	// 	const sdk = getApp().getYouZanYunSdk();
		
	// 	sdk.navigate("homeDashboard", "reLaunch");
	
	// 		},
  toAddCart(){
    
    const sdk = getApp().getYouZanYunSdk();
    sdk.request({
      appName: "babyplanet",
      path: "common/get/accessToken",
      method: "get",
      data:{},
      succeed: (res) => {
        
        console.log(res,122)
        let info=res
        if (info.code == 200) {

          const youzanyun = getApp().getYouZanYunSdk();
          const token = info.data;

          this.data.content.cp.some(item=>{

            console.log(item,111)
            
          const params = {
            "store_id":"",
            "item_id":item.itemId,
            "num":1,
            "activity_type":"",
            "activity_id":"",
            "yz_open_id":this.data.yz_open_id,
            "sku_id":item.skuId,
            "message":""
          };

            console.log(params,222)
          const resp = youzanyun.client.call({
              api: 'youzan.trade.cart.add',
              version: '3.0.0',
              token,
              params,
          });
          console.log(resp,333)
          })
        }
      },
      failed: (err) => {
        console.log("err:", err);
      },
    });
  },
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '防敏问卷调查',
      imageUrl: 'https://img01.yzcdn.cn/upload_files/2023/05/12/Fhfbl4sueSnUCGXGEUQeQ-6wZKxD.jpg',
      path: '/pages/question/index'
    }
  },
  toShare(){
    zanNativeBridge.configShare({
      title: '分享标题',
      desc: '分享描述',
      link: 'https://www.youzan.com',
      imgUrl: 'https://img01.yzcdn.cn/upload_files/2023/05/12/Fhfbl4sueSnUCGXGEUQeQ-6wZKxD.jpg',
      channels: ['appMessage'],
    }).catch(() => {});
  },
  toKefu(){
    const sdk = getApp().getYouZanYunSdk();
sdk
  .openWebview("https://shop121239703.youzan.com/v3/im/index?kdt_id=112185116", "navigate", { youzan: true })
  .then(() => success())
  .catch(() => fail());
  },
  toProduct(e){
    const sdk = getApp().getYouZanYunSdk();
    sdk.navigate("goodsDetail", {alias: e.currentTarget.dataset.alias,goodsPageType:'default' }, "navigateTo");
  },
  toPage(){
    wx.navigateTo({
      url: '/pages/baby-detail/index',
    })
  },
  bindPickerChange1: function(e) {
    this.setData({
      skuIndex:e.detail.value,
    })
  },
});
